package edu.java.lectures.lec12.threads.deadlock.philosophers;

public class PhylosopherDinner {

    private static final int PHYLOSOPHERS_COUNT = 2;

    public static void main(String[] args) {
	Spoon[] spoonArr = new Spoon[PHYLOSOPHERS_COUNT];
	for (int i = 0; i < spoonArr.length; i++) {
	    spoonArr[i] = new Spoon(i + 1);
	}

	Phylosopher[] phylosophersArr = new Phylosopher[PHYLOSOPHERS_COUNT];
	for (int i = 0; i < phylosophersArr.length; i++) {
	    String phylosopherName = "PH-" + (i + 1);
	    Spoon leftSpoon = spoonArr[i];
	    int j = (i == (spoonArr.length - 1)) ? 0 : i + 1;
	    Spoon rightSpoon = spoonArr[j];
	    phylosophersArr[i] = new Phylosopher(phylosopherName, leftSpoon,
		    rightSpoon);
	}

	for (Phylosopher phylosopher : phylosophersArr) {
	    phylosopher.start();
	}
    }
}
